package cn.ylxn.Algorithm;

public class example01 {
    public static void main(String[] args) {
        int[][] arr = new int[3][3];
        arr[0][0]=1;
        arr[0][1]=2;
        arr[0][2]=3;
        arr[1][0]=4;
        arr[1][1]=5;
        arr[1][2]=6;
        arr[2][0]=7;
        arr[2][1]=8;
        arr[2][2]=9;
        int[][] ints = changeTowArr(arr);
        for (int i = 0; i < ints.length; i++) {
            for (int j = 0; j < ints.length; j++) {
                System.out.println(ints[i][j]);
            }
        }
    }
    /**
     * 1 2 3
     * 4 5 6
     * 7 8 9
     *
     * 9 6 3
     * 8 5 2
     * 7 4 1
     */
    public static int[][] changeTowArr(int[][] array){
        if (array.length<0){
            return null;
        }
        int x = array.length;
        int y = array.length;
        int[][] b = new int[x][y];
        for (int m = 0; m < array.length; m++) {
            for (int n = 0; n < array.length; n++) {
                b[Math.abs(y-n)-1][Math.abs(x-m)-1]=array[m][n];
            }
        }
        return b;
    }
}
